<template>
  <show-container title="Classified Edit">
    <Card dis-hover :bordered="false">
      <p slot="title">Classified Edit</p>
      <Form
        :style="{ width: '520px' }"
        :rules="formRules"
        :model="formItem"
        ref="formItem"
        :label-width="180"
      >
        <FormItem label="Classified Name" prop="label">
          <Input v-model="formItem.label" placeholder="Classified Name"></Input>
        </FormItem>
        <FormItem label="Classified sort" prop="sort">
          <Input v-model="formItem.sort" placeholder="Classified sort"></Input>
        </FormItem>
        <FormItem>
          <Button type="primary" :loading="loading" @click="handleUpdate"
            >Save</Button
          >
        </FormItem>
      </Form>
    </Card>
  </show-container>
</template>
<script>
/**
 * 编辑分类
 */
import { updateData } from "@/api/classified.js";
import { AddPageMixin } from "@/mixins/ListMixins.js";
export default {
  mixins: [AddPageMixin],
  data() {
    return {
      formItem: {},
      loading: false,
      formRules: {
        label: [{ required: true, message: "required", trigger: "blur" }],
        sort: [{ required: true, message: "required", trigger: "blur" }]
      }
    };
  },
  created() {
    this.formItem = JSON.parse(this.$route.query.data);
    console.log(this.formItem);
  },
  methods: {
    handleUpdate() {
      this.$refs.formItem.validate(valid => {
        if (valid) {
          updateData(this.formItem).then(() => {
            this.$Message.success("Success");
            this.triggerRefresh();
            this.$closePage();
          });
        }
      });
    }
  }
};
</script>
